﻿using System;
using System.Web;

namespace CE.Sitemap
{
    public class mySiteMapProvider : XmlSiteMapProvider
    {
        public mySiteMapProvider() { }
        public override SiteMapNode FindSiteMapNode(string strUrl)
        {
            // Use the base method to get the url, and check whether the node exists. 

            SiteMapNode smn = base.FindSiteMapNode(strUrl);
            if (smn == null)
            {
                //  if the node is not exist                            
                string[] arrUrl = strUrl.Split('?');
                string sPage = arrUrl[0];    // get the page's url
                string sQuery = string.Empty;
                if (arrUrl.Length >= 2)
                    sQuery = arrUrl[1];     // get the QueryString
                // Bug 修正完畢
                string[] aQuery = sQuery.Split('&');    // split the QueryString
                for (int i = 0; i < aQuery.Length; i++)
                {
                    // try to find the node according to the querystring
                    smn = base.FindSiteMapNode(sPage + "?" + aQuery[i]);
                    if (smn != null)
                    {
                        break;
                    }
                }
                if (smn == null)
                {
                    // cannot find the node, even with the querystring
                    smn = base.FindSiteMapNode(sPage);
                }
            }
            return smn;
        }
    }
}